﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using YoYoMoocExampleApp.Models;

namespace YoYoMoocExampleApp.Pages;

public class IndexModel : PageModel
{
    private readonly ILogger<IndexModel> _logger;

    private readonly IProductRepository _repository;
    private readonly IConfiguration _config;

    public string Message{get; set;}
    public List<Product> Products{ get; set; }


    public string Hostname { get; set; }
    public string DBHOST { get; set; }
    public string DBPORT { get; set; }
    public string DBPASSWORD { get; set; }


    public IndexModel(ILogger<IndexModel> logger,IProductRepository repository,IConfiguration config)
    {
        _logger = logger;
        _repository = repository;
        _config = config;
    }

    public void OnGet()
    {
        Message=_config["MESSAGE"]??"深入浅出 ASP.NET Core与Docker";
        Products=_repository.Products.ToList();


        Hostname=_config["HOSTNAME"];
        DBHOST=_config["DBHOST"]??"localhost";
        DBPORT=_config["DBPORT"]??"3253";
        DBPASSWORD=_config["DBPASSWORD"]??"bb123456";
    }
}
